<template>
    <Layout>
        <Form ref="form1" :model="form1" :label-width="120">
            <Row class="query-form" style="padding-top: 15px">
                <Col span="8">
                    <FormItem label="审计任务：">
                        <!--  <Input class="query-form-el"  type="text" v-model="form1.missionName" ></Input>-->
                        <Select v-model="form1.missionName">
                            <Option v-for="item in missionList" :value="item.missionId" :key="item.missionId"
                                    :label="item.missionName">
                                {{item.missionName}}
                            </Option>
                        </Select>
                    </FormItem>
                </Col>

                <Col span="8">
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>

            <Row class="query-form">
                <Col span="24">
                    <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                </Col>
            </Row>
        </Form>

        <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据！" :loading="buttonLoading" size="small"
               border :columns="columns1" :data="dataTable">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                      @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>

        <Modal :title="add?'整改方案新增':'整改方案修改'" :transfer=false v-model="model1" :width=600>
            <Row>
                <Col span="24">
                    <Form ref="form1datacopy" :model="form1datacopy" :rules="ruleCustom" label-position="top">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="审计任务：" prop="missionId">
                                    <!--{{form1datacopy.missionName}}-->
                                    <Input v-model="form1datacopy.missionName" :readonly="true" @on-focus="openSelect"/>
                                    <!--<Button slot="append" @click="openSelect" icon="ios-search"></Button>-->
                                    <!--</Input>-->
                                </FormItem>
                            </Col>
                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">

                            <Col span="23">
                                <FormItem label="审计单位：">
                                    <Input v-model="form1datacopy.auditedOrgName" :readonly="true"/>
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="组长：" prop="groupLeaderName">
                                    <Input v-model="form1datacopy.groupLeaderName" :readonly="true"/>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="上报人：" prop="groupLeaderName">
                                    <Input v-model="form1datacopy.userName" :readonly="true"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="开始时间：">
                                    <!--{{formatDate(new Date(form1datacopy.planStart), 'yyyy-MM-dd')}}-->
                                    <DatePicker type="date" v-model="form1datacopy.planStart" style="width: 100%"
                                                :readonly="true"></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label="结束时间：">
                                    <!-- {{formatDate(new Date(form1datacopy.planEnd), 'yyyy-MM-dd')}}-->
                                    <DatePicker type="date" v-model="form1datacopy.planEnd" style="width: 100%"
                                                :readonly="true"></DatePicker>
                                </FormItem>
                            </Col>

                        </Row>


                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label="公司领导：" prop="projectManager">
                                    <cascaderDom ref="childUser" @setOrgInfo="setUserId" @setOrgname="setUserName"
                                                 :currentOrgId="form1datacopy.projectManager"
                                                 :currentOrgName="form1datacopy.projectManagerName">
                                    </cascaderDom>
                                </FormItem>
                            </Col>

<!--                            <Col span="11">-->
<!--                                <FormItem label="集团领导：" prop="companyManager">-->
<!--                                    <cascaderDom ref="childUser1" @setOrgInfo="setUserId1" @setOrgname="setUserName1"-->
<!--                                                 :currentOrgId="form1datacopy.companyManager"-->
<!--                                                 :currentOrgName="form1datacopy.companyManagerName">-->
<!--                                    </cascaderDom>-->
<!--                                   -->
<!--                                </FormItem>-->
<!--                            </Col>-->
                            <Col span="11">
                                <FormItem label="集团领导：" prop="groupLeader">
                                    <Select v-model="form1datacopy.companyManager">
                                        <Option v-for="item in groupLeaderList" :value="item.userId" :key="item.userId">
                                            {{item.userName}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>

                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="方案概述：" prop="programmeDesc">
                                    <Input v-model="form1datacopy.programmeDesc" type="textarea" :rows="4"/>
                                </FormItem>
                            </Col>
                        </Row>

                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label="整改方案附件：">
                                    <div>
                                        <Upload ref="upload"
                                                :before-upload="beforeUpload"
                                                :show-upload-list="true"
                                                :max-size="10240"
                                                multiple
                                                type="drag"
                                                :action="fileUrl">
                                            <div style="padding: 10px">
                                                <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                                                <p>点击将文件拖拽到这里上传</p>
                                                <span style="font-size:8px;color: #797a64">支持扩展名：.rar .zip .doc .docx .pdf...</span>
                                            </div>
                                        </Upload>
                                    </div>
                                    <div v-show="uploadList.length>0" v-for="item in uploadList" :key='item'>
                                        <a @click="downloadFile(form1datacopy.programmeId,item)">{{ item.fileName }}</a>
                                        <Button type="text" icon="md-trash" @click="remove1(item.id)"
                                                style="margin-left: 5px;margin-bottom: 3px"/>
                                    </div>
                                </FormItem>
                            </Col>
                        </Row>
                        <!--  <Row type="flex" justify="center" class="code-row-bg">
                              <Col span="23" >
                                  <FormItem>
                                      <Button class='ivu-btn-save' @click="submit('form1datacopy')" >确定</Button>
                                      <Button class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                                  </FormItem>
                              </Col>
                          </Row>-->
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="submit('form1datacopy')">确定</Button>
                <Button class='ivu-btn-cancel' @click="handleCancel">取消</Button>
            </div>
        </Modal>
        <Modal title="方案管理详情" v-model="model2" footer-hide class="modal-view-detail" :width=800>

            <Form :model="form1datacopy" :label-width="160">
                <Row type="flex" justify="space-around">
                    <Col span="23">
                        <FormItem label="审计任务：" prop="stdOrgName">
                            {{form1datacopy.missionName}}
                        </FormItem>
                    </Col>

                </Row>

                <Row type="flex" justify="space-around">
                    <Col span="23">
                        <FormItem label="审计单位：">
                            {{form1datacopy.auditedOrgName}}
                        </FormItem>
                    </Col>


                </Row>
                <Row type="flex" justify="space-around">
                    <Col span="11">
                        <FormItem label="组长：" prop="location">
                            {{form1datacopy.groupLeaderName}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="上报人：" prop="location">
                            {{form1datacopy.userName}}
                        </FormItem>
                    </Col>

                </Row>
                <Row type="flex" justify="space-around">
                    <Col span="11">
                        <FormItem label="开始时间：">
                            {{formatDate(new Date(form1datacopy.planStart), 'yyyy-MM-dd')}}
                        </FormItem>
                    </Col>

                    <Col span="11">
                        <FormItem label="结束时间：">
                            {{formatDate(new Date(form1datacopy.planEnd), 'yyyy-MM-dd')}}
                        </FormItem>
                    </Col>

                </Row>
                <Row type="flex" justify="space-around">
                    <Col span="11">
                        <FormItem label="公司领导：">
                            {{form1datacopy.projectManagerName}}
                        </FormItem>
                    </Col>
                    <Col span="11">
                        <FormItem label="集团领导：">
                            {{form1datacopy.companyManagerName}}
                        </FormItem>
                    </Col>

                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem label="方案概述：">
                            {{form1datacopy.programmeDesc}}
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem label="整改方案附件：">
                            <div v-show="uploadList.length>0" v-for="item in uploadList" :key='item'>
                                <a @click="downloadFile(form1datacopy.programmeId,item)">{{ item.fileName }}</a>
                            </div>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem>
                            <Button class='ivu-btn-save' @click="model2=false">关闭</Button>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        </Modal>

        <Modal title="审计任务选择" :transfer=false footer-hide v-model="missionSelectModal" :width=900>
            <missionSelect ref="selMission" @selectMission="selectMission">
            </missionSelect>
        </Modal>
        <Modal :transfer=false v-model="model3"  :width=900>
            <Tabs>
                <TabPane label="历史记录">
                    <Table ref='table1' border :columns="columns2" no-data-text="没有查询到相关数据！" style="margin-top: 0" :loading="loading2"
                           :data="history" width="100%"  :height="450" highlight-row stripe size="small"></Table>
                </TabPane>
                <TabPane label="流程图">
                    <div style="height: 450px; overflow-y: auto; overflow-x: auto">
                        <img :src="imgUrl" >
                    </div>
                </TabPane>
            </Tabs>
            <div slot="footer">
                <Button @click="model3=false" class="ivu-btn-save">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
    import {Api} from '../../../api/index.js'
    import {sessionStorage} from '../../../common/cacheUtils.js';
    import cascaderDom from '../../../components/cascader-dom.vue';
    import missionSelect from "./missionSelect.vue"

    export default {
        components: {
            cascaderDom, missionSelect
        },
        data() {
            return {
                history : [],
                loading2: false,
                model3:false,
                missionList: [],
                fileUrl: Api.interestedPartiesUserFile,
                auditTypes: [
                    {id: '1', name: "集团审核"},
                    {id: '2', name: "二级集团审核"},
                    {id: '3', name: "自评价"}
                ],
                imgUrl:'',
                groupLeaderList:[],
                columns2: [
                    {
                        type: 'index',
                        title: '序号',
                        width: 80,
                        align: 'center',
                    },
                    {
                        width: 180,
                        title: '审批时间',
                        key: 'endTime',
                        align: 'center',
                    },
                    {
                        width: 185,
                        title: '节点名称',
                        key: 'name',
                        align: 'center',
                    },
                    {
                        width: 120,
                        title: '审批人',
                        key: 'userName',
                        align: 'center'
                    },
                    {
                        width: 100,
                        title: '审批意见',
                        key: 'route',
                        align: 'center'
                    },
                    {
                        width: 200,
                        title: '备注',
                        key: 'opinions',
                        align: 'center'
                    },
                ],
                missionSelectModal: false,
                upLoadList1: [],
                appStatusList: [],
                locationList: [],
                stdRankList: [],
                downloadUrl: Api.downloadMongoFile,
                upUrl: Api.uploadMongoFile,
                form1: {},
                uploadList: [],
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                dataTable: [],
                columns1: [
                    {
                        title: "序号",
                        width: 80,
                        align: "center",
                        fixed: 'left',
                        render: (h, params) => {
                            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
                        }
                    },
                    {
                        title: '状态',
                        align: 'center',
                        key: 'status',
                        minWidth: 80,
                        render: (h, params) => {
                            let color = 'green';
                            if (params.row.procinstState == undefined || params.row.procinstState == null||params.row.procinstState == 2) {
                                color = 'red';
                            }
                            return h('div', [
                                h('span', {
                                    style: {
                                        color: color
                                    }
                                }, params.row.procinstState == 1 ? '审批中' : params.row.procinstState == 2 ? '被退回' : params.row.procinstState == 3 ? '审批通过' : '未上报' || '--')
                            ]);
                        }
                    },
                    {
                        title: '审计任务',
                        minWidth: 300,
                        align: 'center',
                        key: 'missionName',
                    },
                    {
                        title: '公司领导',
                        minWidth: 150,
                        align: 'center',
                        key: 'projectManagerName',
                    },
                    {
                        title: '集团领导',
                        minWidth: 150,
                        align: 'center',
                        key: 'companyManagerName',
                    },
                    {
                        title: '方案概述',
                        minWidth: 300,
                        align: 'center',
                        key: 'programmeDesc',
                    },

                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 300,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px'
                                    },
                                    on: {
                                        click: () => {
                                            this.showData(params, 1);
                                        }
                                    }
                                }, '详情'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? '#d0d0d0' : '',
                                        pointerEvents: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.showData(params, 2);
                                        }
                                    }
                                }, '修改'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? '#d0d0d0' : '',
                                        pointerEvents: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.reportInfo(params.row);

                                        }
                                    }
                                }, '上报'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('A', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? '#d0d0d0' : 'red',
                                        pointerEvents: params.row.procinstState == "1" || params.row.procinstState == "2" || params.row.procinstState == "3" ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.deleteData(params);
                                        }
                                    }
                                }, '删除'),
                                h('Divider', {
                                    props: {
                                        type: 'vertical',
                                    }
                                }, ''),
                                h('a', {
                                    props: {
                                        type: 'primary',
                                    },
                                    style: {
                                        fontSize: '14px',
                                        color: params.row.procinstId == null ? '#d0d0d0' : '',
                                        pointerEvents: params.row.procinstId == null ? 'none' : ''
                                    },
                                    on: {
                                        click: () => {
                                            this.imgUrl = Api.getFlowImg + '/' + params.row.procinstId
                                            this.showHistory(params.row);
                                        }
                                    }
                                },'审批记录')
                            ]);
                        }
                    },

                ],
                ruleCustom: {
                    appraiseScore: {required: true, type: 'number', message: ' ', trigger: 'change'},
                    projectManager: [{
                        validator: (rule, value, callback) => {
                            if (this.form1datacopy.projectManager == undefined ||this.form1datacopy.projectManager == null || this.form1datacopy.projectManager == '' ) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    missionId: [{
                        validator: (rule, value, callback) => {
                            if (this.form1datacopy.missionId == undefined ||this.form1datacopy.missionId == null || this.form1datacopy.missionId == '' ) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],

                    companyManager: [{
                        validator: (rule, value, callback) => {
                            if (this.form1datacopy.companyManager == undefined ||this.form1datacopy.companyManager == null || this.form1datacopy.companyManager == '' ) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],

                },
                auditedOrgName: '',
                auditedOrgId: '',
                add: false,
                model1: false,
                model2: false,
                showdata: {},
                location: null,
                form1datacopy: {},
                files: [],
                buttonLoading: false, tableHeight: 10,
            }
        },
        mounted() {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            //this.selectCodingSort();
            this.$http.get(Api.queryRoleUser + "/" +"dda573b123f9472d95ba3063b25133f7").then((res) => {
                this.groupLeaderList = res.data.data;
            }).catch(e => {
                this.$Message.error("数据获取失败")
            });
            this.query();
        },
        methods: {
            showHistory(row) {
                this.model3 = true;
                this.loading2 = true;
                this.$http.get(Api.getHistory + '/' + row.procinstId, {params: {}}).then((res) => {
                    this.history = res.data;
                    this.loading2 = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            downloadFile(guideId, file) {
                let url = this.fileUrl + '/file/' + file.id;
                this.$http.get(url, {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {
                    console.log(res)
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = file.fileName //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
            remove1(id) {
                console.log(id)
                let url = this.fileUrl + '/file/' + id;
                this.$http.delete(url).then((res) => {
                    this.getFiles()
                })
            },

            beforeUpload(file) {
                console.log(this.uploadList)
                let formData = new FormData();
                formData.append("files", file); // 文件对象
                let url = this.fileUrl + '/' + this.form1datacopy.programmeId + '/files/adtProgramme'
                this.$http.post(url, formData).then((res) => {
                    if (res.data.result == "success") {
                        this.$Message.info("文件上传成功")
                        this.getFiles();
                    }
                })
                return false
            },
            getFiles() {
                let url = this.fileUrl + '/' + this.form1datacopy.programmeId + '/files/adtProgramme'
                this.$http.get(url).then((res) => {
                    if (res.data.result == "success") {
                        this.uploadList = res.data.data
                        console.log(this.uploadList);
                    }
                })
            },
            reportInfo(row) {
                let user = sessionStorage('userId').getObject('userId');
                let istrue = confirm("是否上报该条记录？");
                if (istrue) {
                    this.buttonLoading = true;
                    let data = {
                        key: "adtProgramme",
                        createUserId: user.userId,
                        userName: user.userName,
                        workId: row.programmeId,
                        formKey: "adtProgrammeForApproval",
                        user1: row.projectManager,
                        user2: row.companyManager
                    };
                    this.$http.post(Api.submit, data).then(function (res) {
                        this.buttonLoading = false;
                        this.$Message.success({
                            content: '保存成功',
                            duration: 4
                        });
                        this.query();
                    }, function (err) {
                        this.buttonLoading = false;
                        this.$Message.error({
                            content: '保存失败',
                            duration: 4
                        });
                    });
                }

            },
            onCancel() {
                this.model2 = false
            },
            closeModal1() {
                this.expertSelectModal = false;
            },
            selectMission(row) {
                this.missionSelectModal = false;
                this.form1datacopy.missionName = row.missionName;
                this.form1datacopy.missionId = row.missionId;
                this.form1datacopy.auditTypeName = row.auditTypeName;
                this.form1datacopy.groupLeaderName = row.groupLeaderName;
                this.form1datacopy.auditedOrgName = row.auditedOrgName;
                this.form1datacopy.planStart = this.formatDate(new Date(row.planStart), 'yyyy-MM-dd');
                this.form1datacopy.planEnd = this.formatDate(new Date(row.planEnd), 'yyyy-MM-dd');


            },
            deleteFile(index) {
                this.files.splice(index, 1);
            },
            deleteData(params) {
                let url = Api.deleteAdteProgramme + "/" + params.row.programmeId;
                this.$http.delete(url).then((res) => {
                    if (res.status === 200) {
                        this.$Message.success('成功');
                        this.query()
                    } else if (res.data.status === 201) {
                        this.$Message.error(res.data.msg);

                    }
                }).catch(e => {
                    this.$Message.error('请求失败' + e);
                })
            },

            openSelect() {
                this.missionSelectModal = true
            },
            addInfo() {
                this.form1datacopy = {
                    programmeId: this.get_uuid(),
                    userName: sessionStorage('userId').getObject('userId').userName,

                };

                this.uploadList = [];
                this.model1 = true;
                this.add = true;
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            handleCancel() {
                this.form1datacopy = {};
                this.model1 = false;
            },
            selectCodingSort() {

            },
            reset() {
                this.form1 = {};
                this.query();


            },
            setUserId(data) {
                this.form1datacopy.projectManager = data[data.length - 1];
            },
            setUserName(data) {
                this.form1datacopy.projectManagerName = data;
            },

            setUserId1(data) {
                this.form1datacopy.companyManager = data[data.length - 1];
            },
            setUserName1(data) {
                this.form1datacopy.companyManagerName = data;
            },

            query() {
                this.buttonLoading = true
                let userId = JSON.parse(sessionStorage('paramUserInfo').get('userInfo'))["createUserId"]
                let orgId = sessionStorage('userId').getObject('userId').orgInfo.parentId;
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    orgId: orgId
                };
                let msg = {
                    createOrgId: orgId,
                    auditState: '2',
                }

                this.$http.get(Api.getAllTasksByUseId, {params: {id: userId}}).then((res) => {
                    this.missionList = res.data.data;
                });

                data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                data.missionName = this.form1.missionName || ''
                let url = Api.queryAdtProgramme;

                this.$http.get(url, {params: data}).then((res) => {

                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.buttonLoading = false
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            showData(data, flag) {

                this.auditedOrgId = data.row.auditedOrgId;
                this.auditedOrgName = data.row.auditedOrgName;
                if (flag == 1) {
                    //查看页面
                    this.form1datacopy = data.row;
                    this.model2 = true;
                } else {
                    this.add = false;
                    this.form1datacopy = JSON.parse(JSON.stringify(data.row));

                    this.model1 = true;
                }
                this.getFiles()
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },

            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        //this.form1datacopy.planStart = this.formatDate(new Date(this.form1datacopy.planStart), 'yyyy-MM-dd');
                        //this.form1datacopy.planEnd = this.formatDate(new Date(this.form1datacopy.planEnd), 'yyyy-MM-dd');

                        if (this.add) {
                            let userId = sessionStorage('userId').getObject('userId').userId;
                            let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
                            this.form1datacopy.createUserId = userId;
                            this.form1datacopy.createOrgId = orgId;

                            this.$http.post(Api.saveAdtProgramme, this.form1datacopy).then((res) => {

                                if (res.status === 200) {
                                    this.$Message.success('成功');
                                    this.model1 = false;
                                    this.query()

                                } else if (res.data.status === 201) {
                                    this.$Message.error(res.data.msg);
                                    this.model1 = false;
                                }

                            }).catch(e => {
                                this.model1 = false;
                                this.query();
                                this.$Message.error("数据获取失败")
                            })
                        } else {
                            let userId = sessionStorage('userId').getObject('userId').userId;
                            let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
                            this.form1datacopy.updateUserId = userId;
                            this.form1datacopy.updateOrgId = orgId;
                            this.$http.post(Api.updateAdtProgramme, this.form1datacopy).then((res) => {
                                if (res.status === 200) {
                                    this.$Message.success('成功');
                                    this.model1 = false;
                                    this.query()

                                } else if (res.data.status === 201) {
                                    this.$Message.error(res.data.msg);
                                    this.model1 = false;
                                }

                            }).catch(e => {
                                this.model1 = false;
                                this.query();
                                this.$Message.error("数据获取失败")
                            })
                        }


                    } else {
                        this.$Message.error('请填报完整!');
                    }
                })
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            get_uuid() {
                let s = [];
                let hexDigits = "0123456789abcdef";
                for (let i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4";
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
                s[8] = s[13] = s[18] = s[23] = "-";

                let uuid = s.join("");
                let reg = new RegExp("-", "g");
                let a = uuid.replace(reg, "");
                console.log(a);
                return a;
            },
        },
        watch: {
            "model1": function (qw, er) {
                if (qw && this.model1) {
                    setTimeout(() => {
                        this.$refs.childUser.setCurrentOrg();
                        this.$refs.childUser1.setCurrentOrg();
                    }, 100)
                } else {
                    this.$refs.childUser.resetCurrentOrg();
                    this.$refs.childUser1.resetCurrentOrg();
                }
            },

        },
    }
</script>

<style lang='css' scoped>
    @import '../../../index.css';
</style>
